package cn.kgc.springloud.controller;

import cn.kgc.springloud.entity.Product;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author mosin
 * date 2022/1/4
 * @version 1.0
 */
@RestController
@RequestMapping("/product")
public class ProductController {
    Logger logger = LoggerFactory.getLogger(getClass());
    @Value("${server.port}")
    private int port;
    @GetMapping("/p1")
    public String test01(){
        return "Product service invoke ok :"+port;
    }


    @GetMapping("/p2")
    public String test02(@RequestParam("na") String name, Integer id){
        logger.info("name: {}, id:{}",name,id);
        return "Product service invoke ok :"+port;
    }

    @PostMapping("/p3")
    public String test03(@RequestBody Product product){
        logger.info(product.toString());
        return "Product service invoke ok :"+port;
    }

    @PostMapping("/p4")
    public String test04(String[] ids){
        logger.info(Arrays.toString(ids));
        return "Product service invoke ok :"+port;
    }

    @GetMapping("/p5/{name}/{id}")
    public String test05( @PathVariable String name, @PathVariable Integer id){
        logger.info("name: {}, id:{}",name,id);
        return "Product service invoke ok :"+port;
    }


    @GetMapping("/p6")
    public Product test06(Integer id){
        logger.info("id:{}",id);
        return Product.builder().id(id).name("羽绒服").price(230).build();
    }

    @GetMapping("/p7")
    public List<Product> test07(Integer id){
        logger.info("id:{}",id);
        ArrayList<Product> products = new ArrayList<>();
        Product product = Product.builder().id(id).name("羽绒服").price(230).build();
        products.add(product);
        products.add(product);
        products.add(product);
        products.add(product);
        return products;
    }


}
